package cn.edu.zafu.bigdata.yt.wjcz;

import java.io.*;

public class RhymingWords_yt {
    public static void main(String[] args) throws IOException{
        FileReader words=new FileReader("D:\\Work\\LJava\\LearnJava-5\\src\\main\\java\\cn\\edu\\zafu\\bigdata\\yt\\wjcz\\words.txt");
        Reader rhymedWords =reverse(sort(reverse(words)));
        BufferedReader in =new BufferedReader(rhymedWords);
        String input;
        while((input=in.readLine())!=null)
            System.out.println(input);
        in.close();
    }
    public static Reader reverse(Reader source) throws IOException{
        BufferedReader in =new BufferedReader(source);
        PipedWriter pipeOut=new PipedWriter();
        PipedReader pipeIn=new PipedReader(pipeOut);
        PrintWriter out=new PrintWriter(pipeOut);
        new ReverseThread_yt(out,in).start();
        return pipeIn;
    }
    public static Reader sort(Reader source) throws IOException{
        BufferedReader in =new BufferedReader(source);
        PipedWriter pipeOut=new PipedWriter();
        PipedReader pipeIN=new PipedReader(pipeOut);
        PrintWriter out=new PrintWriter(pipeOut);
        new SortThread_yt(out,in).start();
        return pipeIN;
    }
}
